package com.lulu.baselib.api;


import com.lulu.baselib.api.converter.MyConverterFactory;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * Author: XuChang
 * Date: 2019/10/20 0:32
 * Email: 123286473@qq.com
 * Description:
 * History:
 */
public class ApiService {
    static Retrofit retrofit;

    private static Retrofit getDefaultRetrofit() {
        if (retrofit == null) {
            synchronized (ApiService.class) {
                if (retrofit == null)
                    retrofit = createRetrofit();
            }
        }
        return retrofit;
    }

    private static Retrofit createRetrofit() {
        return new Retrofit.Builder()
                .baseUrl(ApiConstants.HOST)
                .client(OkHttpFactory.getInstance())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                //自动解析json数据
                .addConverterFactory(MyConverterFactory.create())
                .build();
    }


    public static ApiInf getApi() {
        return getDefaultRetrofit().create(ApiInf.class);
    }

}
